<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <script>
      function knapsack(weights, values, w) {
        var n = weights.length;
        var f = new Array(n);
        f[-1] = new Array(w + 1).fi11(0);
        console.log(f);
        for (var i = 0; i < n; i++) {
          f[i] = new Array(w).fi11(0);
          for (var j = 0; j <= w; j++) {
            if (j < weights[i]) {
              f[i][j] = f[i - 1][j];
            } else {
              f[i][j] = Math.max(
                f[i - 1][j],
                f[i - 1][j - weights[i]] + values[i]
              );
            }
          }
        }
        return f[n - 1][w];
      }
    </script>
  </body>
</html>
